@extends("layouts.main")
@section("css")
    <link rel="stylesheet" href="{{asset('/bower_components/jquery-treegrid/css/jquery.treegrid.css')}}">
@endsection


@section("title","新闻分类管理")
@section("page_title","新闻分类管理")
@section("page_small_title","分类列表")

@section("content")
    <div class="box  box-success">
        <div class="box-header">
            <h3 class="box-title">
                <a href="{{url("/admin/news/category/create")}}" class="btn btn-sm btn-success"><i class="fa fa-fw fa-plus-circle"></i>添加</a>
            </h3>

            <div class="box-tools">
                <div class="input-group input-group-sm" style="width: 150px;">
                    <input type="text" name="table_search" class="form-control pull-right" placeholder="Search">
                    <div class="input-group-btn">
                        <button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
                    </div>
                </div>
            </div>
        </div>
        <div class="box-body table-responsive no-padding">
            <table class="table table-hover tree">
                <tr>
                    <th>名称</th>
                    <th>添加时间</th>
                    <th>更新时间</th>
                    <th>操作</th>
                </tr>
                @foreach($categories as $item)
                <tr  class="treegrid-{{$item->id}}{{$item->parent_id?' treegrid-parent-'.$item->parent_id:''}}">
                    <td>{{$item->name}}</td>
                    <td>{{$item->created_at}}</td>
                    <td>{{$item->updated_at}}</td>
                    <td>
                        <a href="{{url("admin/news/category/".$item->id."/edit")}}"><i class="fa fa-edit"></i> </a>
                        <a href="javascript:;" data-id="{{$item->id}}" class="_delete"><i class="fa fa-trash-o text-red"></i></a>
                    </td>
                </tr>
                 @endforeach
            </table>
        </div>
        <div class="box-footer clearfix">
            <ul class="pagination pagination-sm no-margin pull-right">
                <li><a href="#">&laquo;</a></li>
                <li><a href="#">1</a></li>
                <li><a href="#">2</a></li>
                <li><a href="#">3</a></li>
                <li><a href="#">&raquo;</a></li>
            </ul>
        </div>
    </div>
@endsection


@section("script")
    <script type="text/javascript">
         $("._delete").click(function(){
              //获取data属性的值
              var id = $(this).data("id");
              if(confirm("确认删除吗？")){
                    $.post("/admin/news/category/"+id,{'_method':'delete','_token':'{{csrf_token()}}'},function () {
                         window.location.href='{{route('category.index')}}'
                    });
              }
         });
    </script>


    <script type="text/javascript" src="{{asset('/bower_components/jquery-treegrid/js/jquery.treegrid.js')}}"></script>
    <script type="text/javascript" src="{{asset('/bower_components/jquery-treegrid/js/jquery.treegrid.bootstrap3.js')}}"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $('.tree').treegrid();
        });
    </script>
@endsection